-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NNVM][FRONTEND][Keras] Support for reusing layers #1192
Conversation
@Huyuwei, I updated my codes based on your comment. Can you review this? |
nnvm/python/nnvm/frontend/keras.py
Outdated
@@ -475,7 +475,7 @@ def from_keras(model): | |||
symtab = SymbolTable() | |||
for keras_layer in model.layers: | |||
if isinstance(keras_layer, keras.engine.topology.InputLayer): | |||
keras_layer.name = 'data' | |||
keras_layer.name = keras_layer.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line can be removed
nnvm/python/nnvm/frontend/keras.py
Outdated
# we append node index to the symbol name to make it unique. | ||
# The one exception is InputLayer. Changing input variable names after conversion | ||
# would confuse users, so we should keep them as far as possible. Fortunately, | ||
# it's safe because all the input layers have unique names in Keras. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are named to input_1, input_2, input_3 ... by default.
nnvm/python/nnvm/frontend/keras.py
Outdated
if isinstance(pred, keras.engine.topology.InputLayer): | ||
predecessors.append(pred.name) | ||
else: | ||
predecessors.append(pred.name + str(i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pred.name + '_' +str(i) will be clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds better, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the second thought, I think pred.name + ':' + str(i) will be better since Keras also adds '_[num]' suffixes to layer names.
nnvm/python/nnvm/frontend/keras.py
Outdated
|
||
# With the current implementation, _convert_merge and _convert_concat | ||
# expects their inputs to be List. For now, we handle them differently, | ||
# but in future, we could have a unified way here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kazum Keras can't create multiple merge or concat layers from the same name instance, is this correct? Seems this is one assumption here.
Another assumption is keras layers other than merge or concat have only one predecessor. I think this is correct. Can you verify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kazum Keras can't create multiple merge or concat layers from the same name instance, is this correct? Seems this is one assumption here.
I've confirmed it's not correct. I'll add a test case for that and fix the problem.
Another assumption is keras layers other than merge or concat have only one predecessor. I think this is correct. Can you verify it?
Fortunately, looks like the assumption is no longer necessary in the fixed version.
@kazum The new implementation is clean and elegant! |
Moved from dmlc/nnvm#501